<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_wechat_miniapp', function (Blueprint $table) {
            $table->id();
            $table->string('appid')->comment('appid');
            $table->uuid('user_id')->comment('用户id');
            $table->string('openid', 32)->comment('微信openid');
            $table->timestamps();
            $table->unique(['user_id', 'openid'], 'unique_user_openid');
            $table->index('openid', 'idx_openid');
            $table->index(['user_id', 'appid'], 'idx_app_user');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_wechat_miniapp');
    }
};
